#include "qmywidget.h"


#include "../../include/abstractproperty.h"
#include "../../include/qcommonstruct.h"
#include "../../lib/shared/qdatamanager.h"
#include "../../lib/shared/qobjecthost.h"

#include <QVariant>
#include <QMouseEvent>

#include <QPainter>
#include <QStyleOption>

QMyWidget::QMyWidget(QWidget *parent) :
    QWidget(parent),
    m_host(new QObjectHost(this))
{
    setProperty("className","QWidget");
    setProperty("typeName","Widget");
    setProperty("typeIcon",":/images/widgets/widget.png");
    setProperty("needFrame",true);

    m_host->addProperty("Attribute",QStringList()<<"font"<<"focusPolicy"<<"text");
    m_host->addProperty("StyleSheet",QStringList()<<"color"<<"image");
}

void QMyWidget::paintEvent(QPaintEvent *e)
{
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    QWidget::paintEvent(e);
}


void QMyWidget::updateProperty(const QString & name)
{
    if(name=="Z-Value")
    {
        emit zValueChanged();
    }
    m_host->updateStyle(name,true);
}

void QMyWidget::updatePropertyAttribute()
{
    m_host->updatePropertyAttribute();
}

void QMyWidget::initProperty()
{
    if(property("running").toBool())
    {
        m_host->setGlobalObject(sender());
        m_host->initRunningProperty();
    }
}
